import { request } from './request.js'
request.defaultData.baseUrl = 'http://cyjs.pzhkj.cn/'

// {
//   dan1,
//   dan2,
//   dan3,
//   dan4,
//   dan5,
//   dan1cx,
//   dan2cx,
//   dan3cx,
//   dan4cx,
//   dan5cx,
//   small,
//   odd,
//   prime,
//   kuadu,
//   jioubi,
//   daxiaobi,
//   zhihebi,
//   lian,
// }

export function generateZuhao(pendingData) {
  let postData = {}
  Object.keys(pendingData).forEach(keyName => {
    if (typeof pendingData[keyName] !== 'undefined') {
      postData[keyName] = pendingData[keyName]
    }
  })

  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/zuhao/generate',
        method: 'POST',
        data: postData,
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}

export function generateZuhao2(pendingData) {
  let postData = {}
  Object.keys(pendingData).forEach(keyName => {
    if (typeof pendingData[keyName] !== 'undefined') {
      postData[keyName] = pendingData[keyName]
    }
  })

  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/zuhao/generateByDanList',
        method: 'POST',
        data: postData,
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}

export function getOmissionAnalysis({ qishu, caipiao_id, haoma }) {
  return new Promise((resolve, reject) => {
    request
      .ajax({
        path: 'api/zuhao/omissionAnalysis',
        method: 'POST',
        data: {
          qishu,
          caipiao_id,
          haoma,
        },
        afterAjax: res => {
          resolve(res)
        },
      })
      .catch(err => {
        reject(err)
      })
  })
}
